package select;

import java.util.ArrayList;
import java.util.List;

/**
 * 数组的查
 */
public class array {
    //在第i个位置插入元素为e的数
    public static int sleect(ArrayList<Integer> list, int e){
        int low=0;
        int high=list.size()-1;
        int mid;
        while(low<=high){
            mid=(low+high)/2;
            if (list.get(mid)==e){
                return mid;
            }
            if (list.get(mid)<e){
               low=mid+1;
            }
            if (list.get(mid)>e){
                high=mid-1;
            }

        }
        return 0;

    }


    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(3);
        list.add(4);
        list.add(5);
        list.add(6);
        list.add(7);
        int sleect = sleect(list, 3);
        System.out.println(sleect);


    }





}
